package com.yf.dmp.service;

import com.alibaba.fastjson.JSON;
import com.yf.dmp.bean.QueryInfo;
import com.yf.dmp.bean.TableMap;
import com.yf.dmp.dao.TableMapDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class TableMapService {
    @Autowired
    private TableMapDao tmDao;

    public String getTableMap(QueryInfo queryInfo){
        int num = tmDao.getTableMapCount ("%" + queryInfo.getQuery() + "%");
        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        List<TableMap> tm = tmDao.getTableMap("%" + queryInfo.getQuery() + "%", pageStart, queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("num", num);
        res.put("data", tm);
        String jsonstr = JSON.toJSONString(res);
        return jsonstr;
    };

    public int addTableMap(TableMap tm){
        return tmDao.addTableMap(tm);
    };
    public int getTableMapCount(String code){
        return tmDao.getTableMapCount(code);
    };
    public int deleteTableMapById(int id){
        return tmDao.deleteTableMapById(id);
    };
    public TableMap getUpdateTableMap(int id){
        return tmDao.getUpdateTableMap(id);
    };
    public int updateTableMap(TableMap tm){
        return tmDao.updateTableMap(tm);
    };


}
